<template>
	<view class="wrap">
		<view class="header">
			<view class="nav">
				 <view :class="['item', currentNav == 1 ? 'active' : '']" @click="handleNav(1)">已打卡</view>
				 <view :class="['item', currentNav == 2 ? 'active' : '']" @click="handleNav(2)">缺勤</view>
			</view>
			<view class="tab" v-if="currentNav == 1">
				<view :class="['item', tabIndex == index ? 'active' : '']" v-for="(item, index) in tabLists" @click="handleTab(index)">{{item}}</view>
			</view>
		</view>
		<view class="content" v-if="currentNav == 1">
			<view class="lists">
				<block v-if="lists.length > 0">
					<block>
						<view class="item" v-for="(item, index) in lists" :key="index">
							<view class="img_wrap">
								<image :src="item.user.avatar" mode=""></image>
							</view>
							<view class="info">
								<view class="left">
									<view class="name">{{item.user.nickname}}</view>
									<text>{{item.createtime}}</text>
								</view>
								<view class="status">{{item.is_late == 1 ? '迟到' : '正常'}}</view>
							</view>
						</view>
					</block>
				</block>
				<u-empty mode="list" v-else></u-empty>
			</view>
		</view>
		<view class="cont" v-else>
			<view class="lists">
				<block v-if="lists.length > 0">
					<block>
						<view class="item" v-for="(item, index) in lists" :key="index">
							<view class="date">{{item.date}}</view>
							<view class="info">
								<view class="text" v-for="(subItem, subIndex) in item.nuser_ids.split(',')">
									{{subItem}}
								</view>
							</view>
						</view>
					</block>
				</block>
				<u-empty mode="list" v-else></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
import { signDetail } from '../../../api/manager'

	export default {
		data () {
			return {
				currentNav: 1,
				tabLists: ['全部', '正常', '迟到'],
				tabIndex: 0,
				lists: [
					{
						name: '吴丙瑞',
						text: 'VIP部'
					},
					{
						name: '吴丙瑞',
						text: 'VIP部11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'
					},
					{
						name: '吴丙瑞',
						text: 'VIP部'
					},
					{
						name: '吴丙瑞',
						text: 'VIP部'
					}
				],
				start_time: '',
				end_time: '',
				page: 1,
				last_page: 1
			}
		},
		onReachBottom() {
			if (this.currentNav == 2) {
				return
			}
			if(this.page == this.last_page){
				uni.showToast({
					title:'已经是最后一页了',
					icon:'none'
				})
			}else{
				this.page++
				this.getData()
			}
		},
		onLoad (options) {
			this.start_time = options.start_time
			this.end_time = options.end_time
			this.getData()
		},
		methods: {
			async getData () {
				if(this.page == 1){
					this.lists = []
				}
				if (this.currentNav == 1) {
					var params = {
						start_time: this.start_time,
						end_time: this.end_time,
						type1: this.currentNav,
						type2: this.tabIndex + 1,
						page: this.page
					}
				} else {
					var params = {
						start_time: this.start_time,
						end_time: this.end_time,
						type1: this.currentNav,
						page: this.page
					}
				}
				let res = await signDetail(params)
				if (this.currentNav == 1) {
					this.last_page = res.data.last_page
					if (res.code == 1) {
						res.data.data.forEach((item,index) => {
							this.lists.push(item)
						})
					} else {
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				} else {
					this.lists = res.data
				}
			},
			
			handleNav (index) {
				this.currentNav = index
				this.lists = []
				this.page = 1
				this.getData()
			},
			
			handleTab (index) {
				this.tabIndex = index
				this.lists = []
				this.page = 1
				this.getData()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		min-height: 100vh;
		height: fit-content;
		background-color: #F6F6F6;
		box-sizing: border-box;
		
		.header {
			width: 100%;
			height: fit-content;
			box-sizing: border-box;
			background-color: #fff;
			position: fixed;
			z-index: 1;
			
			.nav {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-around;
				height: 60px;
				background-color: #fff;
				box-sizing: border-box;
				
				.item {
					flex: 1;
					text-align: center;
					font-size: 16px;
					border-bottom: 2px solid transparent;
					padding: 15px 0;
					box-sizing: border-box;
				}
				
				.active {
					border-color: #78b0fa;
					color: #0a84ff;
				}
			}
			
			
			.tab {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-around;
				padding: 0 12px;
				box-sizing: border-box;
				border-bottom: 1px solid #ddd;
				height: 50px;
				background-color: #fff;
				box-sizing: border-box;
				
				.item {
					flex: 1;
					text-align: center;
					font-size: 16px;
					padding: 15px 0;
					box-sizing: border-box;
				}
				
				.active {
					color: #0a84ff;
				}
			}
		}
		
		
		.content {	
			min-height: 100vh;
			padding: 125px 0 0;
			box-sizing: border-box;
			background-color: #fff;
			box-sizing: border-box;
			
			.lists {
				
				.item {
					padding: 0 12px;
					box-sizing: border-box;
					display: flex;
					align-items: center;
					
					.img_wrap {
						width: 56px;
						height: 56px;
						border: 1px solid #ddd;
						border-radius: 100%;
						box-sizing: border-box;
						margin-right: 15px;
						
						image {
							width: 100%;
							height: 100%;
							border-radius: 100%;
						}
					}
					
					.info {
						flex: 1;
						display: flex;
						align-items: center;
						justify-content: space-between;
						border-bottom: 1px solid #ccc;
						padding: 15px 0;
						box-sizing: border-box;
						
						.left {
							flex: 1;
							display: flex;
							flex-direction: column;
							
							.name {
								font-size: 18px;
								margin-bottom: 8px;
							}
							
							text {
								display: block;
								width: 60vw;
								font-size: 14px;
								color: #666;
								overflow: hidden;
								white-space: nowrap;
								text-overflow: ellipsis;
								word-break: break-all;
							}
						}
						
						.status {
							font-size: 14px;
							color: #666;
						}
					}
				}
			}
		}
		
		.cont {
			padding: 75px 12px 12px;
			box-sizing: border-box;
			
			.lists {
				
				.item {
					padding: 12px;
					box-sizing: border-box;
					background-color: #fff;
					border-radius: 6px;
					box-sizing: border-box;
					margin-bottom: 12px;
					
					.date {
						font-size: 18px;
						font-weight: bold;
						padding-bottom: 10px;
					}
					
					.info {
						
						.text {
							padding: 12px 0;
							border-bottom: 1px solid #ddd;
						}
					}
				}
			}
		}
	}
</style>